// pages/classify/classify.js
import {
        getClassify
} from '../../netWork/api/apiClassify.js';
import {
        getClassifyData
} from '../../netWork/api/apiClassify';
import {
        getGoddsDetailData
} from '../../netWork/api/apigoodsDetail';
import {
        getShopping
} from '../../netWork/api/apigoodsDetail'
Page({
        /**
         * 页面的初始数据
         */
        data: {
                listData: [],
                ind: -1,
                id: 233471,
                list: [],
                isImg: false,
                num: 1,
                isShow: false,
                setDataList: {},
              
        },
        todetail(e) {
                wx.navigateTo({
                        url: `/pages/goodsDetail/goodsDetail?id=${e.currentTarget.dataset.id}`,
                        success: function (res) {

                        }
                })
        },
        toCart(e) {

                let item = e.currentTarget.dataset.itemall
                let {
                        id,
                        minBuyNumber
                } = item
                getShopping(id, minBuyNumber).then(res => {
                        let lzh = res.data.data.times
                        wx.showToast({
                                title: '成功',
                                icon: 'success',
                                duration: 2000
                        })

                        wx.setStorageSync('changeCart', lzh)
                })

        },
        delcover() {
                this.setData({
                        isShow: false
                })
        },
        setdeta(e) {
                this.setData({
                        isShow: true
                })
                getGoddsDetailData(e.currentTarget.dataset.tag).then(res => {
                        console.log(res.data.data);
                        this.setData({
                                setDataList: res.data.data
                        })
                });


        },
        delnum() {
                if (this.data.num <= 1) {
                        this.setData({
                                num: 1
                        })
                } else {
                        let numdata = this.data.num - 1
                        this.setData({
                                num: numdata
                        })
                }

        },
        addnum() {

                let numdata = this.data.num + 1
                this.setData({
                        num: numdata
                })

        },
        addcart(e) {
                console.log(e);
                // let id = e.currentTarget.dataset.cartitem.basicInfo.id
                // let minBuyNumber = e.currentTarget.dataset.cartitem.basicInfo.minBuyNumber

                let item = e.currentTarget.dataset.cartitem.basicInfo
                let {
                        id,
                        minBuyNumber
                } = item
                // minBuyNumber = this.data.num
                console.log(id);
                getShopping(id, minBuyNumber).then(res => {
                        // let lzh = res.data.data.times
                        console.log(res);
                        // wx.reLaunch({
                        //         url: "/pages/shopCart/shopCart"
                        // })
                        wx.setStorageSync('changeCart', lzh)
                })

        },
        cartColor(e) {
                console.log(this.data.ind);
                this.setData({
                        ind: e.currentTarget.dataset.ind
                })
        },
        // 搜索方法 key为用户输入的查询字段
        enter() {
                if (!this.data.sosu) {
                        return false
                } else {
                        wx.reLaunch({
                                url: '/pages/searchData/searchData?sosu=' + this.data.sosu,
                        })
                }
        },

        // 输入框的值
        input(e) {
                this.setData({
                        sosu: e.detail.value
                })
        },

        // 左侧导航
        cut(e) {
                // console.log(this.data.list);
                this.setData({
                        ind: e.currentTarget.dataset.index,
                        id: e.currentTarget.dataset.item.id
                })
                getClassifyData(this.data.id).then(res => {
                        this.setData({
                                list: res.data.data
                        })
                })

                if (this.data.list == undefined) {
                        this.setData({
                                isImg: false
                        })
                } else {
                        this.setData({
                                isImg: true
                        })
                }
        },
        /**
         * 生命周期函数--监听页面加载
         */
        onLoad: function (options) {

                getClassify().then(res => {
                        this.setData({
                                listData: res.data.data
                        })
                });

                getClassifyData(this.data.id).then(res => {

                        this.setData({
                                list: res.data.data
                        })
                });
        },

        /**
         * 生命周期函数--监听页面初次渲染完成
         */
        onReady: function () {

        },

        /**
         * 生命周期函数--监听页面显示
         */
        onShow: function () {

        },

        /**
         * 生命周期函数--监听页面隐藏
         */
        onHide: function () {

        },

        /**
         * 生命周期函数--监听页面卸载
         */
        onUnload: function () {

        },

        /**
         * 页面相关事件处理函数--监听用户下拉动作
         */
        onPullDownRefresh: function () {

        },

        /**
         * 页面上拉触底事件的处理函数
         */
        onReachBottom: function () {
                // console.log(111111);
        },

        /**
         * 用户点击右上角分享
         */
        onShareAppMessage: function () {

        }
})